package com.sky.controller.common;

import com.sky.exception.ServiceException;
import com.sky.service.OssService;
import com.sky.utils.AliOssUtil;
import com.sky.utils.DateUtils;
import com.sky.web.controller.BaseController;
import com.sky.web.domain.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @Author tzl
 * @Date 2023-07-08 20:51:03  星期六
 * @Description: 通用接口
 */
@Slf4j
@Api(tags = "通用接口")
@RestController
@RequestMapping("/admin/common")
public class CommonController extends BaseController {


    @Autowired
    private OssService ossService;

    /**
     * 文件上传
     * @param file 文件
     * @return
     */
    @ApiOperation(value = "文件上传")
    @PostMapping("/upload")
    public AjaxResult upload(MultipartFile file){
        log.info("文件上传：{}",file);
        String url = ossService.upload(file,"dish");
        if (url == null) {
            return AjaxResult.error("上传失败");
        }
        return AjaxResult.success("上传成功",url);
    }
}
